package com.vsoontech.audiorecorder;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private BeepManager mManager;

    // Used to load the 'native-lib' library on application startup.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        BeepManagerPro beepManagerPro = new BeepManagerPro();
//        beepManagerPro.init();
//        beepManagerPro.play();

        int result = NativeAudioRecorder.initAudioRecorder();
        Log.i(TAG, "onCreate: " + result);

        mManager = new BeepManager();
        mManager.play();
        new Thread(new Runnable() {
            @Override
            public void run() {
                SystemClock.sleep(3000);
                while (true) {
                    PcmData pcmData = NativeAudioRecorder.readPcmData();
                    if (pcmData.buffer != null) {
                        mManager.pushData(pcmData.buffer);
                        Log.i(TAG, "PcmData: " + pcmData.length);
                    } else {
                        Log.i(TAG, "Nelson run: Read Null");
                    }
                }
            }
        }).start();
    }

    public void onClick(View view) {

    }


}
